package test.clone;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class DeepCloneClass implements Serializable {

	private String str;
	private int number;
	private DeepTypeClass typeClass;

	public DeepCloneClass deepClone() throws IOException, ClassNotFoundException {
		DeepCloneClass deepClass = null;
		ByteArrayOutputStream bous = new ByteArrayOutputStream();
		ObjectOutputStream obos = new ObjectOutputStream(bous);
		obos.writeObject(this);
		obos.close();

		ByteArrayInputStream bins = new ByteArrayInputStream(bous.toByteArray());
		ObjectInputStream obins = new ObjectInputStream(bins);
		deepClass = (DeepCloneClass) obins.readObject();
		return deepClass;
	}

	/**
	 * @return the str
	 */
	public String getStr() {
		return str;
	}

	/**
	 * @param str
	 *            the str to set
	 */
	public void setStr(String str) {
		this.str = str;
	}

	/**
	 * @return the number
	 */
	public int getNumber() {
		return number;
	}

	/**
	 * @param number
	 *            the number to set
	 */
	public void setNumber(int number) {
		this.number = number;
	}

	/**
	 * @return the typeClass
	 */
	public DeepTypeClass getTypeClass() {
		return typeClass;
	}

	/**
	 * @param typeClass
	 *            the typeClass to set
	 */
	public void setTypeClass(DeepTypeClass typeClass) {
		this.typeClass = typeClass;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "CloneClass [str=" + str + ", number=" + number + ", typeClass=" + typeClass + "]";
	}
}
